<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义弹窗示例</title>
    <style>
        /* 样式定义 */
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .modal {
            display: none; /* 初始隐藏 */
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgb(0,0,0);
            background-color: rgba(0,0,0,0.4); /* 黑色背景带透明 */
        }
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto; /* 15% 从顶部 */
            padding: 20px;
            border: 1px solid #888;
            width: 80%; /* 可根据需要调整 */
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>
<body>

<div id="myModal" class="modal">
    <div class="modal-content">
        <span class="close">&times;</span>
        <p>请输入口令:</p>
        <input type="text" id="customPromptInput" placeholder="例如1328">
    </div>
</div>

<script>
    // 获取模态弹窗
    var modal = document.getElementById("myModal");
    var span = document.getElementsByClassName("close")[0];
    var input = document.getElementById("customPromptInput");

    // 显示弹窗
    function showModal() {
        modal.style.display = "block";

        // 设置自动关闭计时器
        var timer = setTimeout(function() {
            if (input.value.trim() === "") {
                modal.style.display = "none";
                console.log("弹窗因无操作在五秒后自动关闭");
            }
        }, 5000); // 5秒

        // 监听输入框变化，如果有输入则清除计时器
        input.addEventListener('input', function() {
            clearTimeout(timer);
        });

        // 点击关闭按钮
        span.onclick = function() {
            modal.style.display = "none";
        }

        // 点击弹窗外部区域关闭弹窗
        window.onclick = function(event) {
            if (event.target == modal) {
                modal.style.display = "none";
            }
        }
    }

    // 显示弹窗
    showModal();

    // 你可以在这里添加其他逻辑，比如表单提交时检查输入等
</script>

</body>
</html>